package com.kuzlak.cms.module.base;

import net.coobird.thumbnailator.Thumbnails;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.IOException;

@Service
public class ThumbnailService {

    public void createThumbnail(String sourceImagePath, String destinationImagePath, int width, int height) {
        try {
            Thumbnails.of(new File(sourceImagePath))
                    //.size(width, height) // 设置缩略图尺寸
                    .width(400)
                    .keepAspectRatio(true) // 保持原图像的宽高比
                    .toFile(new File(destinationImagePath));

            System.out.println("Thumbnail created successfully.");
        } catch (IOException e) {
            System.err.println("Error creating thumbnail: " + e.getMessage());
        }
    }
}
